'''
http://lists.ironpython.com/pipermail/users-ironpython.com/2006-January/001654.html
'''

import sys

def readTestFile(f):
    while 1:
            line = f.readline()
            if line:
                print line
                for c in line:
                    print '%s %02x %4d' % (c, ord(c), ord(c))
            else:
                    break


print 'reading the pythonic way' 
print '\nreading with ISO-8859-1'
print 'chr hex dec'
sys.setdefaultencoding('ISO-8859-1')
f = open(r'ansi_1.txt', 'r')
readTestFile (f)
f.close()

try:
    print '\nreading with utf8'
    print 'chr hex dec'
    sys.setdefaultencoding('utf8')
    f = open(r'ansi_1.txt', 'r')
    readTestFile (f)
    f.close()
except:
    print "Sorry can't change setdefaultencoding"

try: 
    print '\nreading with ASCII'
    print 'chr hex dec'
    sys.setdefaultencoding('ASCII')
    f = open(r'ansi_1.txt', 'r')
    readTestFile (f)
    f.close()
except:
    print "Sorry can't change setdefaultencoding"

print '''\n\ndefault encoding seems to affect
1. how the code is interpretated' 
2. the behavier of open and write

Currently I have not yet found a way to change encoding used by read in a single
IronPython module. Using multiple mudule with different defaultencoding may work
'''
